/************************************************************
 * Project Name         [Thinking_In_Java]
 * File Name            [NotepadFileFilter.java]
 * Creation Date        [11-Jul-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_02_gui.notepad_V1.ui.file;

import java.io.File;

import javax.swing.filechooser.FileFilter;

/**
 * 文件过滤器
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public class NotepadFileFilter extends FileFilter {

	private final String extension;

	public NotepadFileFilter(String extension) {
		this.extension = extension;
	}

	@Override
	public boolean accept(File f) {
		return f.isDirectory() || f.getName().endsWith(extension);
	}

	@Override
	public String getDescription() {
		if (extension.equals("txt")) {
			return "记事本文件(*.txt)";
		}
		if (extension.equals("sql")) {
			return "SQL文件(*.sql)";
		}
		if (extension.equals("java")) {
			return "JAVA源文件 (*.java)";
		}
		return "";
	}
}
